<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_islandMultiPolygonData"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_islandMultiPolygonData"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_addData" onclick="addData()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_removeData" onclick="removeData()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, layer, vectorLayer, dataAdded = false,
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
        url = host + "/iserver/services/map-world/rest/maps/World";
    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation(),
            ]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        vectorLayer = new SuperMap.Layer.Vector("vector", {renderers: ["Canvas"]});
    }

    function addLayer() {

        map.addLayers([layer, vectorLayer]);
        //显示地图范围
        map.setCenter(new SuperMap.LonLat(20, 0), 0);
    }

    function addData() {
        widgets.alert.clearAlert();
        if (!dataAdded) {
            vectorLayer.removeAllFeatures();


            //导洞的创建方式
            var points1 = [
                new SuperMap.Geometry.Point(-20, -20),
                new SuperMap.Geometry.Point(20, -20),
                new SuperMap.Geometry.Point(20, 20),
                new SuperMap.Geometry.Point(-20, 20),
                new SuperMap.Geometry.Point(-20, -20)
            ];
            var line1 = new SuperMap.Geometry.LinearRing(points1);
            var points2 = [
                new SuperMap.Geometry.Point(-10, -10),
                new SuperMap.Geometry.Point(10, -10),
                new SuperMap.Geometry.Point(10, 10),
                new SuperMap.Geometry.Point(-10, 10),
                new SuperMap.Geometry.Point(-10, -10)
            ];
            var line2 = new SuperMap.Geometry.LinearRing(points2);
            var regionDaodong = new SuperMap.Geometry.Polygon([line1, line2]);
            var regionDaodongVector = new SuperMap.Feature.Vector(regionDaodong);

            //多面的创建方式
            var points3 = [
                new SuperMap.Geometry.Point(30, -20),
                new SuperMap.Geometry.Point(70, -20),
                new SuperMap.Geometry.Point(70, 20),
                new SuperMap.Geometry.Point(30, 20),
                new SuperMap.Geometry.Point(30, -20)
            ];
            var line3 = new SuperMap.Geometry.LinearRing(points3);
            var points4 = [
                new SuperMap.Geometry.Point(40, -10),
                new SuperMap.Geometry.Point(60, -10),
                new SuperMap.Geometry.Point(60, 10),
                new SuperMap.Geometry.Point(40, 10),
                new SuperMap.Geometry.Point(40, -10)
            ];
            var line4 = new SuperMap.Geometry.LinearRing(points4);
            var polygon1 = new SuperMap.Geometry.Polygon([line3]);
            var polygon2 = new SuperMap.Geometry.Polygon([line4]);

            var multiPolygon = new SuperMap.Geometry.MultiPolygon([polygon1, polygon2]);
            var regionDduomianVector = new SuperMap.Feature.Vector(multiPolygon);


            vectorLayer.addFeatures([regionDaodongVector, regionDduomianVector]);

            dataAdded = true;
        } else {
            widgets.alert.showAlert(resources.msg_loadedData, true, 240);
        }
    }

    function removeData() {
        widgets.alert.clearAlert();
        dataAdded = false;
        vectorLayer.removeAllFeatures();
        vectorLayer.refresh();
    }

</script>
</body>
</html>